import wx

class GARunDialog(wx.Dialog):
	
	def __init__(self):
		wx.Dialog.__init__(self, None, -1, 'Running an Genetic Algoritm', size=(558, 408))
		
		okButton = wx.Button(self, wx.ID_OK, "OK", pos=(387, 353))
		cancelButton = wx.Button(self, wx.ID_CANCEL, "Cancel", pos=(470, 353))
		wx.StaticLine(self, -1, pos=(4, 343), size=(542, 2)) #bottom spliting button line
		
		self.populationPanel = PopulationPanel(self, pos=(196, 4), size=(349, 333))
		self.parentSelectionPanel = ParentSelectionPanel(self, pos=(196, 4), size=(349, 333))
		self.recombinationPanel = RecombinationPanel(self, pos=(196, 4), size=(349, 333))
		self.mutationPanel = MutationPanel(self, pos=(196, 4), size=(349, 333))
		self.survivorSelectionPanel = SurvivorSelectionPanel(self, pos=(196, 4), size=(349, 333))
		
		self.populationPanel.Hide()
		self.parentSelectionPanel.Hide()
		self.recombinationPanel.Hide()
		self.mutationPanel.Hide()
		self.survivorSelectionPanel.Hide()
		
		self.MakeLeftList()

	def MakeLeftList(self):
		data = (("Populacao",				self.populationPanel),
				("Seleccao de pais",			self.parentSelectionPanel),
				("Recombinacao",			self.recombinationPanel),
				("Mutacao",				self.mutationPanel),
				("Seleccao de sobreviventes",	self.survivorSelectionPanel))
		
		self.list = wx.ListBox(self, -1, (4, 4), (182, 333), [], wx.LB_SINGLE)
		for label, panel in data:
			self.list.Append(label, panel)
		
		self.Bind(wx.EVT_LISTBOX, self.ListBoxItemSelected, self.list)

	def ListBoxItemSelected(self, event):
		list = event.GetEventObject()
		panel = list.GetClientData(list.GetSelection())
		
		panels = [self.populationPanel, self.parentSelectionPanel, self.recombinationPanel, self.mutationPanel, self.survivorSelectionPanel]
		
		for otherPanel in panels:
			if otherPanel != None:
				otherPanel.Show(otherPanel == panel)


class PopulationPanel(wx.Panel):

	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		box = wx.StaticBox(self, -1,"Variacao da populacao", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,32,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinPopSizeMin = wx.SpinCtrl(self, -1, "20", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinPopSizeMax = wx.SpinCtrl(self, -1, "20", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinPopSizeJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))


class ParentSelectionPanel(wx.Panel):

	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### Participant number ###
		box = wx.StaticBox(self, -1,"Diferentes Torneios", pos=(0, 5), size=(348, 90))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,32,125,17)						# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)				# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])			# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])			# size reference to sp1, 50 is the sizeX needed for this one
		s3=(s1[0]+6,s1[1]+s1[3]+s1[1]/2+4,70,s1[3])	# in the other line - you go down by adding the size of the text and delta (in this case 4 (cause of the spins) and half of the line1 position)  to the first line position
		sp3=(s3[0]+s3[2],s3[1]-2,50,sp1[3])			#equal to sp2
		
		wx.StaticText(self, -1, "Numero de participantes:", pos=(s1[0],s1[1]))
		self.spinFightersMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinFightersMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinFightersJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		
		### Loosers hype ###
		wx.StaticBox(self, -1,"Torneamento Estocastico", pos=(0,105), size=(348, 90))
		
		# same stuf as above ...
		s1=(10,132,200,17)
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])
		s3=(s1[0]+6,s1[1]+s1[3]+13+4,70,s1[3])
		sp3=(s3[0]+s3[2],s3[1]-2,50,sp1[3])
		
		wx.StaticText(self, -1, "Probabilidade do perdedor ser escolhido:", pos=(s1[0],s1[1]))
		self.spinLoosersHypeMin = wx.SpinCtrl(self, -1, "0", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinLoosersHypeMax = wx.SpinCtrl(self, -1, "0", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinLoosersHypeJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))



	"""
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		box = wx.StaticBox(self, -1, "Metodo", pos=(0, 0), size=(348, 178))
		
		self.radioAUE = wx.RadioButton(self, -1, "Amostragem universal estocastica", style = wx.RB_GROUP, pos=(10, 19))
		self.radioRoleta = wx.RadioButton(self, -1, "Por roleta", pos=(10, 42))
		self.radioRanking = wx.RadioButton(self, -1, "Por ranking", pos=(10, 65))
		self.radioTorneio = wx.RadioButton(self, -1, "Por torneio", pos=(10, 88))
		
		wx.StaticText(self, -1, "% de prob. de escolher o vencedor", pos=(88, 145))
		wx.StaticText(self, -1, "participantes", pos=(88, 115))
		
		self.spinTournamentParticipants = wx.SpinCtrl(self, -1, "", (32, 110), (50, -1))
		self.spinTournamentWinnerProbability = wx.SpinCtrl(self, -1, "", (32, 140), (50, -1))
		
		self.spinTournamentParticipants.Enable(False)
		self.spinTournamentWinnerProbability.Enable(False)
		
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioAUE)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioRoleta)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioRanking)
		self.Bind(wx.EVT_RADIOBUTTON, self.OnRadioSelect, self.radioTorneio)

	def OnRadioSelect(self, event):
		if event.GetEventObject() is self.radioTorneio:
			self.spinTournamentParticipants.Enable(True)
			self.spinTournamentWinnerProbability.Enable(True)
		else:
			self.spinTournamentParticipants.Enable(False)
			self.spinTournamentWinnerProbability.Enable(False)
	"""

class RecombinationPanel(wx.Panel):

	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### PROBABILIDADE DE RECOMBINACAO###
		box = wx.StaticBox(self, -1,"Probabilidade de Recombinacao", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,5+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinRecProbMin = wx.SpinCtrl(self, -1, "0.70", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinRecProbMax = wx.SpinCtrl(self, -1, "0.70", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinRecProbJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		
		### N POINTS CORTE ###
		box = wx.StaticBox(self, -1,"Quantidade de Pontos de Corte", pos=(0, 80), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,80+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinCutPointsMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinCutPointsMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinCutPointsJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		
		### PESO (WTF) ###
		box = wx.StaticBox(self, -1,"Peso (WTF!!)", pos=(0, 155), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,155+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinWeightMin = wx.SpinCtrl(self, -1, "2", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinWeightMax = wx.SpinCtrl(self, -1, "2", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinWeightJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))



class MutationPanel(wx.Panel):
	
	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### PROBABILIDADE DE MUTACAO###
		box = wx.StaticBox(self, -1,"Probabilidade de Mutacao", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,5+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinMutProbMin = wx.SpinCtrl(self, -1, "0.70", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinMutProbMax = wx.SpinCtrl(self, -1, "0.70", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinMutProbJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		
		### ALFA ###
		box = wx.StaticBox(self, -1,"Alfa", pos=(0, 80), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,80+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinAlfaMin = wx.SpinCtrl(self, -1, "1", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinAlfaMax = wx.SpinCtrl(self, -1, "1", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinAlfaJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))
		
		### SIGMA ###
		box = wx.StaticBox(self, -1,"Sigma", pos=(0, 155), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,155+27,17,17)				# pos initial, sizeY is the default
		sp1=(s1[0]+s1[2],s1[1]-2,55,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],55,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinSigmaMin = wx.SpinCtrl(self, -1, "0.05", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinSigmaMax = wx.SpinCtrl(self, -1, "0.05", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinSigmaJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))


class SurvivorSelectionPanel(wx.Panel):

	def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TAB_TRAVERSAL|wx.NO_BORDER, name=wx.PanelNameStr):
		wx.Panel.__init__(self, parent, id, pos, size, style, name)
		
		### ELITISMO ###
		box = wx.StaticBox(self, -1,"Elitistas", pos=(0, 5), size=(348, 66))
		
		# this variables state the (posX,posY,sizeX,sizeY) of the panel objects
		# they refere to the pos and size of other objects to make thier owns
		s1=(10,5+27,17,17)				# pos initial, sizeY is the default, 27 is the distance to the StaticBox
		sp1=(s1[0]+s1[2],s1[1]-2,50,21)		# a little higher then s1 sinse it's bigger in Y, sizeX is the needed for this
		s2=(sp1[0]+sp1[2]+6,s1[1],12,s1[3])	# the 6 is the space between the spin and the text, 12 is the text size
		sp2=(s2[0]+s2[2],sp1[1],50,sp1[3])	# size reference to sp1, 50 is the sizeX needed for this one
		s3=(sp2[0]+sp2[2]+6,s1[1],70,s1[3])	# 70 is the text size
		sp3=(s3[0]+s3[2],sp1[1],50,sp1[3])	#equal to sp2
		
		wx.StaticText(self, -1, "De", pos=(s1[0],s1[1]))
		self.spinMutProbMin = wx.SpinCtrl(self, -1, "1", pos=(sp1[0],sp1[1]),size=(sp1[2],sp1[3]))
		wx.StaticText(self, -1, "a", pos=(s2[0],s2[1]))
		self.spinMutProbMax = wx.SpinCtrl(self, -1, "1", pos=(sp2[0],sp2[1]),size=(sp2[2],sp2[3]))
		wx.StaticText(self, -1, "com saltos de", pos=(s3[0],s3[1]))
		self.spinMutProbJumps = wx.SpinCtrl(self, -1, "0", pos=(sp3[0],sp3[1]),size=(sp3[2],sp3[3]))

